Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
	''' <summary>
	''' Strongly-typed collection for the MembersThreads class.
	''' </summary>
	<Serializable> _
	Public Partial Class MembersThreadsCollection 
	Inherits ActiveList(Of MembersThreads, MembersThreadsCollection)
	    Public Sub New()
		End Sub
	End Class
	''' <summary>
	''' This is an ActiveRecord class which wraps the MembersThreads table.
	''' </summary>
	<Serializable> _
	Public Partial Class MembersThreads 
	Inherits ActiveRecord(Of MembersThreads)
		#Region ".ctors and Default Settings"
		
		Public Sub New()
			SetSQLProps()
			InitSetDefaults()
			MarkNew()
		End Sub
		
		Public Sub New(ByVal useDatabaseDefaults As Boolean)
			SetSQLProps()
			If useDatabaseDefaults = True Then
				ForceDefaults()
			End If
			MarkNew()
		End Sub
		Public Sub New(ByVal keyID As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByKey(keyID)
		End Sub
		Public Sub New(ByVal columnName As String, ByVal columnValue As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByParam(columnName,columnValue)
		End Sub
		Private Sub InitSetDefaults()
			SetDefaults()
		End Sub
		
		Protected Shared Sub SetSQLProps()
			GetTableSchema()
		End Sub
		#End Region
		
		#Region "Schema and Query Accessor"
		
		Public Shared ReadOnly Property Schema() As TableSchema.Table
			Get
				If BaseSchema Is Nothing Then
					SetSQLProps()
				End If
				Return BaseSchema
			End Get
		End Property
		Private Shared Sub GetTableSchema()
			If (Not IsSchemaInitialized) Then
				'Schema declaration
				Dim schema As TableSchema.Table = New TableSchema.Table("MembersThreads", TableType.Table, DataService.GetInstance("ClubStarterKitData"))
				schema.Columns = New TableSchema.TableColumnCollection()
				schema.SchemaName = "dbo"
				'columns
				
                
                Dim colvarMemberid As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarMemberid.ColumnName = "memberid"
                colvarMemberid.DataType = DbType.Guid
                colvarMemberid.MaxLength = 0
                colvarMemberid.AutoIncrement = false
                colvarMemberid.IsNullable = false
                colvarMemberid.IsPrimaryKey = true
                colvarMemberid.IsForeignKey = true
                colvarMemberid.IsReadOnly = false
                
                
				colvarMemberid.ForeignKeyTableName = "MemberInfo"
                
                schema.Columns.Add(colvarMemberid)
                
                Dim colvarThreadid As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarThreadid.ColumnName = "threadid"
                colvarThreadid.DataType = DbType.Int32
                colvarThreadid.MaxLength = 0
                colvarThreadid.AutoIncrement = false
                colvarThreadid.IsNullable = false
                colvarThreadid.IsPrimaryKey = true
                colvarThreadid.IsForeignKey = true
                colvarThreadid.IsReadOnly = false
                
                
				colvarThreadid.ForeignKeyTableName = "Threads"
                
                schema.Columns.Add(colvarThreadid)
                
                Dim colvarLastread As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarLastread.ColumnName = "lastread"
                colvarLastread.DataType = DbType.DateTime
                colvarLastread.MaxLength = 0
                colvarLastread.AutoIncrement = false
                colvarLastread.IsNullable = false
                colvarLastread.IsPrimaryKey = false
                colvarLastread.IsForeignKey = false
                colvarLastread.IsReadOnly = false
                
                
                schema.Columns.Add(colvarLastread)
                
                Dim colvarWatch As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarWatch.ColumnName = "watch"
                colvarWatch.DataType = DbType.Boolean
                colvarWatch.MaxLength = 0
                colvarWatch.AutoIncrement = false
                colvarWatch.IsNullable = false
                colvarWatch.IsPrimaryKey = false
                colvarWatch.IsForeignKey = false
                colvarWatch.IsReadOnly = false
                
						colvarWatch.DefaultSetting = "((0))"
				
                
                schema.Columns.Add(colvarWatch)
                
				BaseSchema = schema
				
				'add this schema to the provider
                'so we can query it later
                DataService.Providers("ClubStarterKitData").AddSchema("MembersThreads",schema)
			End If
		End Sub
		Public Shared Function CreateQuery() As Query
			Return New Query(Schema)
		End Function
		
		#End Region
		
		#Region "Props"
	
          
        <XmlAttribute("Memberid")> _
        Public Property Memberid As Guid 
			Get
				Return GetColumnValue(Of Guid)("memberid")
			End Get
		    
			Set
				SetColumnValue("memberid", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Threadid")> _
        Public Property Threadid As Integer 
			Get
				Return GetColumnValue(Of Integer)("threadid")
			End Get
		    
			Set
				SetColumnValue("threadid", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Lastread")> _
        Public Property Lastread As DateTime 
			Get
				Return GetColumnValue(Of DateTime)("lastread")
			End Get
		    
			Set
				SetColumnValue("lastread", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Watch")> _
        Public Property Watch As Boolean 
			Get
				Return GetColumnValue(Of Boolean)("watch")
			End Get
		    
			Set
				SetColumnValue("watch", Value)
			End Set
		End Property
		
		
		
		
		#End Region
		
		
			    
	    
		
		
		
		
		
	    
	    #Region "ForeignKey Methods"
	    
		''' <summary>
		''' Returns a MemberInfo ActiveRecord object related to this MembersThreads
		''' </summary>
		Public Property MemberInfo() As Data.MemberInfo
			Get
				Return Data.MemberInfo.FetchByID(Me.Memberid)
			End Get
			Set
				SetColumnValue("memberid", Value.Memberid)
			End Set
		End Property
	    
		''' <summary>
		''' Returns a Threads ActiveRecord object related to this MembersThreads
		''' </summary>
		Public Property Threads() As Data.Threads
			Get
				Return Data.Threads.FetchByID(Me.Threadid)
			End Get
			Set
				SetColumnValue("threadid", Value.Threadid)
			End Set
		End Property
	    
	    #End Region
	    
		
	    
	    'no ManyToMany tables defined (0)
	    
		
		#Region "ObjectDataSource support"
		
		''' <summary>
		''' Inserts a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Insert(ByVal varMemberid As Guid,ByVal varThreadid As Integer,ByVal varLastread As DateTime,ByVal varWatch As Boolean)
			Dim item As MembersThreads = New MembersThreads()
			
            item.Memberid = varMemberid
            
            item.Threadid = varThreadid
            
            item.Lastread = varLastread
            
            item.Watch = varWatch
            
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		''' <summary>
		''' Updates a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Update(ByVal varMemberid As Guid,ByVal varThreadid As Integer,ByVal varLastread As DateTime,ByVal varWatch As Boolean)
			Dim item As MembersThreads = New MembersThreads()
		    
                item.Memberid = varMemberid
				
                item.Threadid = varThreadid
				
                item.Lastread = varLastread
				
                item.Watch = varWatch
				
			item.IsNew = False
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		#End Region
		#Region "Columns Struct"
		Public Structure Columns
			Dim x as Integer
			
            Public Shared Memberid As String = "memberid"
            
            Public Shared Threadid As String = "threadid"
            
            Public Shared Lastread As String = "lastread"
            
            Public Shared Watch As String = "watch"
            
		End Structure
		#End Region
	End Class
End Namespace
